<!--
 * @Author: lixb
 * @Date: 2020-09-04 10:14:53
 * @LastEditTime: 2020-09-07 16:23:18
 * @Descripttion: 薪享卡对账详情
-->
<template>
  <div>
    <el-card>
      {{ rowData.date }}
    </el-card>
    <el-card class="title-search card-box">
      <el-form ref="formInline" :inline="true" :model="formInline">
        <el-form-item label="员工姓名" prop="userName">
          <el-input v-model="formInline.userName" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="所属部门" prop="deptName">
          <el-input v-model="formInline.deptName" placeholder="请输入部门名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="resetDate('formInline')">重置</el-button>
          <el-button type="primary" @click="getTableList()">查询</el-button>
          <el-button type="primary" @click="exportExcel()">导出</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="main-card">
      <Table
        :table-data="tableData"
        :prop-data="propData"
        :table-index="true"
        :paging-data="pagingData"
        @getTableList="getTableList"
      >
        <template slot="op">
          <el-table-column prop="op" fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="detail(scope.row)">查看关联订单</el-button>
            </template>
          </el-table-column>
        </template>
      </Table>
    </el-card>
  </div>
</template>
<script>
  import Table from '@/components/Table';
  import { downloadBlob } from '@/utils/download';
  import { getAdvanceBillDetailList, advanceBillDetailExcelFile } from '@/api/careCard';
  export default {
    components: { Table },
    data() {
      return {
        formInline: {
          userName: '',
          deptName: '',
        },
        rowData: {},
        billDate: '',
        tableData: [],
        propData: [
          {
            prop: 'realName',
            label: '员工姓名',
          },
          {
            prop: 'deptName',
            label: '所属部门',
          },
          {
            prop: 'mobilePhone',
            label: '联系电话',
          },
          {
            prop: 'loginName',
            label: '用户账号',
          },
          {
            prop: 'orderNumber',
            label: '订单总数合计',
          },
          {
            prop: 'orderAmount',
            label: '订单总金额',
          },
          {
            prop: 'payType',
            label: '支付方式',
          },
          {
            prop: 'payAmount',
            label: '支付金额',
          },
          {
            prop: 'op',
            label: '操作',
            type: 'op',
          },
        ],
        pagingData: {
          total: 10,
          current: 1,
          size: 10,
        },
      };
    },
    activated() {
      this.rowData = this.$route.query;
      this.getTableList();
    },
    methods: {
      getTableList() {
        let params = {
          billId: this.rowData.id,
          current: this.pagingData.current,
          size: this.pagingData.size,
          realName: this.formInline.userName,
          deptName: this.formInline.deptName,
        };
        getAdvanceBillDetailList(params).then(res => {
          if (res.status == 200) {
            this.tableData = res.data.records;
            this.pagingData.total = res.data.total;
          }
        });
      },
      detail(row) {
        this.$router.push({
          path: '/careCard/relationOrder',
          query: {
            billDetailId: row.billDetailId,
            date: row.billDate,
            userId: row.userId,
            realName: row.realName,
            deptName: row.deptName,
            orderNumber: row.orderNumber,
            orderAmount: row.orderAmount,
            payAmount: row.payAmount,
          },
        });
      },
      resetDate(formName) {
        this.$refs[formName].resetFields();
      },
      async exportExcel() {
        const params = {
          billId: this.rowData.id,
          current: this.pagingData.current,
          size: this.pagingData.size,
          realName: this.formInline.userName,
          deptName: this.formInline.deptName,
        };
        const res = await advanceBillDetailExcelFile(params);
        downloadBlob(res.data, res.filename);
        this.$message.success('导出成功！');
      },
    },
  };
</script>
<style lang="scss" scoped>
  .title-search {
    margin-top: 15px;
    div {
      display: inline-block;
      margin-right: 30px;
      span {
        color: #7f848b;
      }
    }
  }
  .main-card {
    margin-top: 15px;
  }
</style>
